package org.jtb.flickrportlet;

import org.jtb.quickr.ContactsGetListCriteria;
import org.jtb.quickr.ContactsGetPublicListCriteria;
import org.jtb.quickr.ContactsResponse;
import org.jtb.quickr.ContactsService;
import org.jtb.quickr.PeopleService;
import org.jtb.quickr.PersonResponse;
import org.jtb.quickr.QuickrException;
import org.jtb.quickr.UserResponse;

public class MyHandler {
    private PrefsBean prefsBean;
    private MyBean myBean;
    
    
    public void load(MyBean myBean) throws QuickrException {
        String nsId = findByUserName(prefsBean.getUserName());
        
        PeopleService ps = new PeopleService();
        PersonResponse pr = ps.getInfo(nsId);
        myBean.setBuddyIconUrl(pr.getBuddyIconUrl());
    }
    
    private String findByUserName(String userName) throws QuickrException {
        PeopleService ps = new PeopleService();
        UserResponse ur = ps.findByUserName(userName);
        String userId = ur.getNsId();
        
        return userId;
    }

    public void setPrefsBean(PrefsBean prefsBean) {
        this.prefsBean = prefsBean;
    }

    public void setMyBean(MyBean myBean) throws QuickrException {
        this.myBean = myBean;

        if (prefsBean.getUserName() != null && prefsBean.getUserName().length() > 0) {
            if (!myBean.isLoaded()) {
                load(myBean);
            }
        }
    }
}
